/*
 * Powered By cuichen
 * Since 2014 - 2018
 */package com.seeyoui.kensite.bussiness.orderlang.outbound.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.common.base.service.BaseService;

import java.util.*;

import com.seeyoui.kensite.common.base.domain.EasyUIDataGrid;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;
import com.seeyoui.kensite.common.util.*;
import com.seeyoui.kensite.common.constants.StringConstant;
import com.seeyoui.kensite.bussiness.orderlang.order.domain.Order;
import com.seeyoui.kensite.bussiness.orderlang.outbound.domain.Outbound;
import com.seeyoui.kensite.bussiness.orderlang.outbound.domain.OutboundProductVO;
import com.seeyoui.kensite.bussiness.orderlang.outbound.domain.OutboundVO;
import com.seeyoui.kensite.bussiness.orderlang.outbound.persistence.OutboundMapper;

/**
 * Outbound
 * @author cuichen
 * @version 2.0
 * @since 1.0
 * @date 2018-03-01
 */

@Service
public class OutboundService extends BaseService {
	
	@Autowired
	private OutboundMapper outboundMapper;

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public Outbound findOne(String id) throws CRUDException{
		return outboundMapper.findOne(id);
	}
	
	/**
	 * 查询数据集合
	 * @param outbound
	 * @return
	 * @throws CRUDException
	 */
	public List<Outbound> findList(Outbound outbound) throws CRUDException {
		return outboundMapper.findList(outbound);
	}
	
	/**
     * 出库界面加载商品列表
     * @param outbound
     * @return
     * @throws CRUDException
     */
    public List<OutboundProductVO> findOutboundProduct(String deliveryId) throws CRUDException {
        return outboundMapper.findOutboundProduct(deliveryId);
    }
	
	/**
     * 查询数据集合
     * @param outbound
     * @return
     * @throws CRUDException
     */
    public List<Order> findListRelationOrder(Map map) throws CRUDException {
        return outboundMapper.findListRelationOrder(map);
    }
    
    /**
     * 查询数据集合
     * @param outbound
     * @return
     * @throws CRUDException
     */
    public List<OutboundVO> findInboundOrOutboundList(Map map, String type) throws CRUDException {
        if(StringUtils.isEmpty(type)){
            // 查询出入库信息
            return outboundMapper.findInboundOrOutboundList(map);
        }else if("0".equals(type)){
            // 查询出库信息
            return outboundMapper.findOutboundList(map);
        }else if("1".equals(type)){
            // 查询入库信息
            return outboundMapper.findInboundList(map);
        }
        return null;
    }
	
	/**
	 * 查询所有数据集合
	 * @param outbound
	 * @return
	 * @throws CRUDException
	 */
	public List<Outbound> findAll(Outbound outbound) throws CRUDException {
		return outboundMapper.findAll(outbound);
	}
	
	/**
	 * 查询数据总数
	 * @param outbound
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(Outbound outbound) throws CRUDException {
		return outboundMapper.findTotal(outbound);
	}
	
	/**
     * 查询数据总数
     * @param outbound
     * @return
     * @throws CRUDException
     */
    public int findTotalRelationOrder(Map map) throws CRUDException {
        return outboundMapper.findTotalRelationOrder(map);
    }
	
	/**
	 * 查询数据总数排除当前数据
	 * @param outbound
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(Outbound outbound) throws CRUDException {
		return outboundMapper.findExTotal(outbound);
	}
	
	/**
	 * 数据新增
	 * @param outbound
	 * @throws CRUDException
	 */
	public void save(Outbound outbound) throws CRUDException{
		outbound.preInsert();
		outboundMapper.save(outbound);
	}
	
	/**
	 * 数据修改
	 * @param outbound
	 * @throws CRUDException
	 */
	public void update(Outbound outbound) throws CRUDException{
		outbound.preUpdate();
		outboundMapper.update(outbound);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		outboundMapper.delete(listId);
	}
	
	/**
	 * 数据假删除
	 * @param outbound
	 * @throws CRUDException
	 */
	public void remove(Outbound outbound) throws CRUDException{
		outbound.preUpdate();
		outboundMapper.remove(outbound);			
	}
	/**
     * 查询出入库数据总数
     * @param outbound
     * @return
     */
    public int findTotalInboundOrOutboundList(Map map, String type) {
        if(StringUtils.isEmpty(type)){
            // 查询出入库信息
            return outboundMapper.findTotalOutboundList(map)+outboundMapper.findTotalInboundList(map);
        }else if("0".equals(type)){
            // 查询出库信息
            return outboundMapper.findTotalOutboundList(map);
        }else if("1".equals(type)){
            // 查询入库信息
            return outboundMapper.findTotalInboundList(map);
        }else{
            return 0;
        }
    }
	
}